package com.aviva.config;

import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.ServletContext;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;


public class AppInitializer implements WebApplicationInitializer {
	static Logger log = Logger.getLogger(AppInitializer.class.getName());
	public static String env = "dev"; 
	

	public void onStartup(ServletContext container) {
		// Create the 'root' Spring application context
		Date start=new Date();
		log.log(Level.INFO, "Spring Context is initializing......");
		AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
		AppInitializer.env = ctx.getEnvironment().getProperty("env");
		if(env==null){
			log.log(Level.WARNING, "environment is not defined. Continue as dev environment......");
			AppInitializer.env = "dev";
		}
		ctx.getEnvironment().setActiveProfiles(env);
		ctx.register(AppConfig.class);
		ctx.refresh();
		Date end = new Date();
		log.log(Level.INFO, "Spring Context is initialized in " + (end.getTime() - start.getTime()) + " miliseconds");
	}

}
